//---------------------------------------------------------------------------

#ifndef MainH
#define MainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "YbCommDevice.h"
#include <Chart.hpp>
#include <ExtCtrls.hpp>
#include <FileCtrl.hpp>
#include <Series.hpp>
#include <TeEngine.hpp>
#include <TeeProcs.hpp>
#include <Menus.hpp>
#include <Buttons.hpp>
#include <ComCtrls.hpp>
#include "UI.h"
#include <Dialogs.hpp>
#include <ScktComp.hpp>
#include <NMUDP.hpp>
#include "TeeSeriesStats.hpp"
#include <TeeFunci.hpp>
#include "TeeTools.hpp"
#include "TeeLighting.hpp"

typedef struct {
     UINT8 dir;
     UINT8 num;
     char* type;
     char* param[4];
}TCmdMSG;

typedef struct __packed{
	UINT8  head1;
	UINT8  head2;
	UINT8  cmd;
	UINT8  dir;
	UINT16 dev_id;
	union{	
		UINT8	  u8_val;
		UINT16       u16_val;
		UINT32	  u32_val;
		float f32_val;
		struct{
			UINT8 pad[4];
		}__pad;
	}param;
	UINT8 check;
}TCommMsg;
//---------------------------------------------------------------------------
class TForm1 : public TForm ,public MyUI
{
__published:	// IDE-managed Components
        TGroupBox *grp1;
        TGroupBox *grp2;
        TFileListBox *fllst1;
        TDirectoryListBox *dirlst1;
        TMainMenu *mm1;
        TMenuItem *N1;
        TMenuItem *N2;
        TMenuItem *N3;
        TMemo *mmoinfo;
        TPopupMenu *pm1;
        TMenuItem *N4;
        TMenuItem *N5;
        TMenuItem *N6;
        TPanel *pnl1;
        TBitBtn *btn_arrival;
        TBitBtn *btn_level;
        TPageControl *pgc1;
        TTabSheet *ts1;
        TTabSheet *ts2;
        TBitBtn *btnSave;
        TBitBtn *btnClear;
        TBitBtn *btnPause;
        TGroupBox *grp3;
        TLabeledEdit *ledt_PK1;
        TLabeledEdit *ledt_up_kg;
        TLabeledEdit *ledt_dw_kg;
        TTabSheet *ts3;
        TGroupBox *grp4;
        TGroupBox *grp5;
        TLabeledEdit *ledt_ad1;
        TLabeledEdit *ledt_zero1;
        TLabeledEdit *ledt_K1;
        TLabeledEdit *ledt_ad2;
        TLabeledEdit *ledt_zero2;
        TLabeledEdit *ledt_K2;
        TLabeledEdit *ledt_diff1;
        TLabeledEdit *ledt_zero;
        TChart *cht1;
        TFastLineSeries *ser1;
        TFastLineSeries *ser2;
        TFastLineSeries *ser3;
        TLabeledEdit *ledt_Filter1;
        TLabeledEdit *ledt_Filter2;
        TButton *btnSync;
        TLabeledEdit *ledt_read_page;
        TLabeledEdit *ledt_write_page;
        TButton *btn_change_static;
        TGroupBox *grp6;
        TLabeledEdit *ledt_time;
        TLabeledEdit *ledt_date;
        TMenuItem *N7;
        TLabeledEdit *ledt_diff2;
        TTimer *tmr1;
        TShape *shp1;
        TLabel *lbl_comm;
        TLabeledEdit *ledt_ver;
        TTabSheet *ts4;
        TMemo *mmo_weight;
        TLabeledEdit *ledt_PK2;
        TLabeledEdit *ledt_PSK;
        TMenuItem *N8;
        TButton *btnSim;
        TButton *btnClrData;
        TButton *btnPauseShow;
        TCheckBox *chkAck;
        TLabeledEdit *ledt_axisnum;
        TLabeledEdit *ledt_axisweight;
        TSaveDialog *dlgSave1;
        TMenuItem *N9;
        TTabSheet *ts5;
        TGroupBox *grp7;
        TShape *input1;
        TShape *input2;
        TShape *input3;
        TShape *input4;
        TShape *input5;
        TLabeledEdit *ledt_reset_num;
        TBitBtn *btnChange;
        TMenuItem *N10;
        TFastLineSeries *ser4;
        TLabeledEdit *ledt_kg;
        TBitBtn *btn_zero;
        TBitBtn *btn_k;
        TLabeledEdit *ledt_ad_diff1;
        TLabeledEdit *ledt_ad_diff2;
        TLabeledEdit *ledt_kg1;
        TLabeledEdit *ledt_kg2;
        TLabeledEdit *ledt_total_kg;
        TLabeledEdit *ledt_fama;
        TBitBtn *btn_K2;
        TBitBtn *btnSysK;
        TBitBtn *btn_save_k;
        TLabeledEdit *ledt_SK;
        TLabeledEdit *ledt_mode;
        TLabel *lbl_mode;
        TLabeledEdit *ledt_static_weight;
        TClientSocket *clt1;
        TMenuItem *N11;
        TMenuItem *AD1;
        TMenuItem *AD2;
        TMenuItem *MenuWeight;
        TMenuItem *MenuGm;
        TButton *btnCalib;
        TMenuItem *N12;
        TNMUDP *nmdp_wave;
        TMemo *mmo_alarm;
        TTabSheet *ts6;
        TButton *btn1;
        TButton *btn2;
        TTimer *tmr2;
        TEdit *edt3;
        TLabel *lbl1;
        TButton *btn3;
        TButton *btn4;
        TLabeledEdit *ledt_div;
        TLabeledEdit *ledt_bus;
        TLabeledEdit *ledt_dotnum;
        TLabeledEdit *ledt_zerospd;
        TLabeledEdit *ledt_zerostop;
        TLabeledEdit *ledt_pwrspan;
        TLabeledEdit *ledt_hdspan;
        TLabeledEdit *ledt_full_load;
        TCursorTool *charttool1;
        TLabel *lbl2;
        TFullScreenTool *flscrntlChartTool2;
        TDrawLineTool *drwlntlChartTool2;
        TGroupBox *grp8;
        TLabeledEdit *ledt_spk;
        TLabeledEdit *ledt_spk1;
        TLabeledEdit *ledt_spk3;
        TLabeledEdit *ledt_spk2;
        TLabeledEdit *ledt_spk4;
        TLabeledEdit *ledt_spk5;
        TLabeledEdit *ledt_dynamic_div;
        TButton *btn5;
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall btnParamClick(TObject *Sender);
        void __fastcall cht1MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
        void __fastcall com1CommNotify(TObject *Sender, int NotifyType);
        void __fastcall btnPauseClick(TObject *Sender);
        void __fastcall btnClearClick(TObject *Sender);
        void __fastcall N6Click(TObject *Sender);
        void __fastcall ledt_zero1KeyUp(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall ledt_K1KeyUp(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
        void __fastcall ledt_up_kgKeyUp(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall ledt_Filter1KeyUp(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall ledt_Filter2KeyUp(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall btnSyncClick(TObject *Sender);
        void __fastcall dirlst1Change(TObject *Sender);
        void __fastcall fllst1DblClick(TObject *Sender);
        void __fastcall ledt_read_pageKeyUp(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall ledt_write_pageKeyUp(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall ledt_read_pageDblClick(TObject *Sender);
        void __fastcall ledt_write_pageDblClick(TObject *Sender);
        void __fastcall btn_arrivalClick(TObject *Sender);
        void __fastcall btn_levelClick(TObject *Sender);
        void __fastcall ledt_ad1DblClick(TObject *Sender);
        void __fastcall ledt_1DblClick(TObject *Sender);
        void __fastcall btn_change_staticClick(TObject *Sender);
        void __fastcall ledt_timeDblClick(TObject *Sender);
        void __fastcall N7Click(TObject *Sender);
        void __fastcall btnAckClick(TObject *Sender);
        void __fastcall N8Click(TObject *Sender);
        void __fastcall btnSimClick(TObject *Sender);
        void __fastcall btnClrDataClick(TObject *Sender);
        void __fastcall btnPauseShowClick(TObject *Sender);
        void __fastcall chkAckClick(TObject *Sender);
        void __fastcall ledt_axisnumDblClick(TObject *Sender);
        void __fastcall N9Click(TObject *Sender);
        void __fastcall ledt_reset_numDblClick(TObject *Sender);
        void __fastcall ledt_reset_numKeyPress(TObject *Sender, char &Key);
        void __fastcall btnChangeClick(TObject *Sender);
        void __fastcall N10Click(TObject *Sender);
        void __fastcall btn_zeroClick(TObject *Sender);
        void __fastcall btn_kClick(TObject *Sender);
        void __fastcall btn_K2Click(TObject *Sender);
        void __fastcall btnSysKClick(TObject *Sender);
        void __fastcall btn_save_kClick(TObject *Sender);
        void __fastcall FormShow(TObject *Sender);
        void __fastcall ledt_modeDblClick(TObject *Sender);
        void __fastcall ledt_modeKeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_PK1DblClick(TObject *Sender);
        void __fastcall ledt_PK2DblClick(TObject *Sender);
        void __fastcall ledt_PSKDblClick(TObject *Sender);
        void __fastcall ledt_PK1KeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_PK2KeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_PSKKeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_verDblClick(TObject *Sender);
        void __fastcall ledt_static_weightDblClick(TObject *Sender);
        void __fastcall clt1Read(TObject *Sender,
          TCustomWinSocket *Socket);
        void __fastcall AD1Click(TObject *Sender);
        void __fastcall AD2Click(TObject *Sender);
        void __fastcall MenuGmClick(TObject *Sender);
        void __fastcall MenuWeightClick(TObject *Sender);
        void __fastcall menusaveClick(TObject *Sender);
        void __fastcall ledt_up_kgDblClick(TObject *Sender);
        void __fastcall ledt_dw_kgDblClick(TObject *Sender);
        void __fastcall ledt_dw_kgKeyUp(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall ledt_kk2KeyUp(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall ledt_K1DblClick(TObject *Sender);
        void __fastcall ledt_K2DblClick(TObject *Sender);
        void __fastcall ledt_SKDblClick(TObject *Sender);
        void __fastcall ledt_SKKeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_K1KeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_K2KeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_zero1DblClick(TObject *Sender);
        void __fastcall ledt_zero2DblClick(TObject *Sender);
        void __fastcall ledt_zero2KeyUp(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall ledt_Filter1DblClick(TObject *Sender);
        void __fastcall ledt_Filter2DblClick(TObject *Sender);
        void __fastcall btnCalibClick(TObject *Sender);
        void __fastcall nmdp_waveDataReceived(TComponent *Sender,
          int NumberBytes, AnsiString FromIP, int Port);
        void __fastcall N12Click(TObject *Sender);
        void __fastcall tmr1Timer(TObject *Sender);
        void __fastcall cht1AfterDraw(TObject *Sender);
        void __fastcall btn1Click(TObject *Sender);
        void __fastcall tmr2Timer(TObject *Sender);
        void __fastcall btn2Click(TObject *Sender);
        void __fastcall btn3Click(TObject *Sender);
        void __fastcall btnSaveClick(TObject *Sender);
        void __fastcall btn4Click(TObject *Sender);
        void __fastcall ledt_divDblClick(TObject *Sender);
        void __fastcall ledt_divKeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_zerospdDblClick(TObject *Sender);
        void __fastcall ledt_zerospdKeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_zerostopDblClick(TObject *Sender);
        void __fastcall ledt_pwrspanDblClick(TObject *Sender);
        void __fastcall ledt_hdspanDblClick(TObject *Sender);
        void __fastcall ledt_full_loadDblClick(TObject *Sender);
        void __fastcall ledt_hdspanKeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_pwrspanKeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_full_loadKeyPress(TObject *Sender, char &Key);
        void __fastcall charttool1Change(TCursorTool *Sender, int x, int y,
          const double XValue, const double YValue, TChartSeries *Series,
          int ValueIndex);
        void __fastcall ledt_spkDblClick(TObject *Sender);
        void __fastcall ledt_spk1DblClick(TObject *Sender);
        void __fastcall ledt_spk3DblClick(TObject *Sender);
        void __fastcall ledt_spk2DblClick(TObject *Sender);
        void __fastcall ledt_spk4DblClick(TObject *Sender);
        void __fastcall ledt_spk5DblClick(TObject *Sender);
        void __fastcall ledt_spkKeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_spk1KeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_spk2KeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_spk3KeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_spk4KeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_spk5KeyPress(TObject *Sender, char &Key);
        void __fastcall ledt_dynamic_divDblClick(TObject *Sender);
        void __fastcall ledt_dynamic_divKeyPress(TObject *Sender,
          char &Key);
        void __fastcall btn5Click(TObject *Sender);
private:	// User declarations
        void  __fastcall diffshow(int ad);
        void __fastcall anlysisAD(UINT16 ad1, UINT16 ad2);
        void __fastcall anlysisAD(INT32 ad);
        void __fastcall buildCMD(TCommMsg* msg);
        void __fastcall sendReadCMD(UINT8 cmd);
        void __fastcall sendWriteCMD(TLabeledEdit* ctrl,UINT8 cmd);
        void HowDo(TCommunication* Commu,CBusiness *pSender,TProFrame *pPf);
        void __fastcall setK(double k1, double k2, double k3);
public:		// User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
